﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using ProgrammersFAQ.BE;

namespace ProgrammersFAQ.WS
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "ProductService" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select ProductService.svc or ProductService.svc.cs at the Solution Explorer and start debugging.
    public class ProductService : IProductService
    {
        public void DoWork()
        {
        }

        public Product[] getProductListByPlatform(int platformId)
        {
            using (ProgrammersFAQEntities entities = new ProgrammersFAQEntities())
            {
                return (from a in entities.Products
                        where a.platform_id == platformId
                        select a).ToArray();
            }
        }

        public string getProductListComboByPlatform(int platformId)
        {
            string result = "";
            using (ProgrammersFAQEntities entities = new ProgrammersFAQEntities())
            {
                Product[] productList =  (from a in entities.Products
                                            where a.platform_id == platformId
                                            select a).ToArray();

                foreach (Product product in productList)
                {
                    result += "<option value=\"" + product.id + "\">" + product.product1 + "</option>";
                }
            }
            return result;
        }
    }
}
